package com.songlanyun.modules.personaldata.controller.admin;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.songlanyun.common.annotation.SysLog;
import com.songlanyun.common.validator.ValidatorUtils;
import com.songlanyun.common.validator.group.UpdateGroup;
import com.songlanyun.modules.user.controller.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.songlanyun.modules.personaldata.entity.PersonalDataEntity;
import com.songlanyun.modules.personaldata.service.PersonalDataService;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;

import javax.validation.Validator;


/**
 * 关于我们-个人资料
 *
 * @author wuchao
 * @email sunlightcs@gmail.com
 * @date 2021-03-30 14:34:07
 */
@RestController
@RequestMapping("admin/personal/data")
public class PersonalDataAdminController extends AbstractController {
    @Autowired
    private PersonalDataService personalDataService;

    /**
     * 列表
     */
    @GetMapping("/list")
    //@RequiresPermissions("personaldata:personaldata:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = personalDataService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    //@RequiresPermissions("personaldata:personaldata:info")
    public R info(@PathVariable("id") Integer id) {
        PersonalDataEntity personalData = personalDataService.getById(id);

        return R.ok().put("data", personalData);
    }

    /**
     * 处理
     */
    @SysLog("处理个人资料")
    @PostMapping("/dispose")
    //@RequiresPermissions("personaldata:personaldata:save")
    public R dispose(@RequestBody PersonalDataEntity personalData) {
        ValidatorUtils.validateEntity(personalData, UpdateGroup.class);
        verifyAdmin();
        personalDataService.dispose(personalData);

        return R.ok();
    }


    /**
     * 删除
     */
    @SysLog("删除个人资料")
    @DeleteMapping("/delete/{id}")
    //@RequiresPermissions("personaldata:personaldata:delete")
    public R delete(@PathVariable("id") Long id) {
        verifyAdmin();
        personalDataService.removeById(id);

        return R.ok();
    }

}
